package com.app.hanoitips.travel.welcome;


import com.app.hanoitips.travel.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Handler;
import android.view.View;

public class WelcomView extends View{
	Bitmap welc,ourBg,footStep1,footStep2;
	float changingY;
	Paint textPaint;
	Typeface font;
	Rect middleRect,bg;
	Handler timeHandler;
	Runnable timeRunable;
	long startTime = 0;
	
	public WelcomView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		welc=BitmapFactory.decodeResource(getResources(),R.drawable.welcome);
		ourBg=BitmapFactory.decodeResource(getResources(),R.drawable.welcome_bg);
		footStep1=BitmapFactory.decodeResource(getResources(),R.drawable.dog_1);
		footStep2=BitmapFactory.decodeResource(getResources(),R.drawable.dog);
		font=Typeface.createFromAsset(context.getAssets(), "A BITE.otf");
		FontView();
		PicView();
	}
	public void FontView(){
		textPaint =new Paint();
		textPaint.setColor(Color.CYAN);;
		
		textPaint.setTextAlign(Align.CENTER);
		textPaint.setTextSize(50);
		textPaint.setTypeface(font);
	}
	public void PicView(){
	    middleRect=new Rect();
	    bg=new Rect();

	}
	@Override
	protected void onDraw(final Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		//canvas.drawColor(R.drawable.welcome_bg);
		canvas.drawBitmap(ourBg, null, bg, null);
		canvas.drawText("INCONNEX",(canvas.getWidth()/2), 200, textPaint);
		canvas.drawBitmap(welc, (canvas.getWidth()/4), changingY, null);
		if(changingY<canvas.getHeight()){
			changingY +=10;
		}else{
			changingY =0;
		}
		timeHandler=new Handler();
		timeRunable=new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				long millis = System.currentTimeMillis() - startTime;
	            int seconds = (int) (millis / 1000);
	            if(seconds==1000){
	            	canvas.drawBitmap(footStep1,(canvas.getWidth()-100),(canvas.getHeight()-200), null);
	            	canvas.drawBitmap(footStep2, (canvas.getWidth()-100),(canvas.getHeight()-200), null);
	            }
	            /**if(seconds==2000){
	            	canvas.drawBitmap(footStep1, (canvas.getWidth()/2),(canvas.getHeight()/2), null);
		    	canvas.drawBitmap(footStep2, (canvas.getWidth()/2),(canvas.getHeight()/2), null);	
	            }
	            if(seconds==3000){
	            	canvas.drawBitmap(footStep1, (canvas.getWidth()/4),(canvas.getHeight()/4), null);
		    		canvas.drawBitmap(footStep2, (canvas.getWidth()/4),(canvas.getHeight()/4), null);
	            }**/
	            timeHandler.postDelayed(this, 500);
			}
		};
		bg.set(0, 0, canvas.getWidth(), canvas.getHeight());
		//timeHandler.removeCallbacks(timeRunable);
		invalidate();
	}

	 
}
